package com.star.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description 全局过滤器
 * @Author xtp
 * @Date 2024/1/9 10:49
 */
@Order(-200)
@Component
public class AuthorizeFilter implements GlobalFilter {

    /**
     * 全局过滤器
     * @param exchange 请求上下文，可以获取Request、Response等信息
     * @param chain 用来把请求委托给下一个过滤器
     * @return
     */
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        /*// 1. 获取请求参数
        ServerHttpRequest request = exchange.getRequest();
        MultiValueMap<String, String> params = request.getQueryParams();
        // 2.获取参数中的authorization 参数
        String auth = params.getFirst("authorization");

        // 5.1 设置状态码
        // 5.2 拦截请求
        return exchange.getResponse().setComplete();*/

        return chain.filter(exchange);
    }
}
